<script>
import api from '@/request/api.js'
import { configSDK } from '@/utils/jssdk.js'
export default {
  globalData: {
    session_key: '',
    openid: '',
    hasLogin: '',
    nickName: '',
    avatarUrl: '',
    nft_address: '',
    /* 用户实名认证信息 */
    is_auth: '',
    /* 登录token */
    token: '',
    /* 用户uid */
    uid: '',
  },
  onLaunch: function () {
    // uni.downloadFile({
    //   url:
    //     'https://publish.onedaen.com/uploads/material/23-01-10/167335547224141.png',
    //   // 发行时间背景
    //   success: (res) => {
    //     // const day = new Date()
    //   },
    // })
    // https://publish.onedaen.com//uploads/material/23-01-10/167335547224141.png'
    // console.log('App Launch')
    // const url = 'https://h5.onedaen.com'
    // configSDK(url, {
    //   title: '首页',
    //   desc: '测试分享',
    //   link: url,
    //   imgUrl: '',
    // })
    // 隐藏tabbar
    // uni.hideTabBar()
    /* 从本地缓存读取数据 */
    // 验证登录token是否过期
    setTimeout(() => {
      uni.getStorage({
        key: 'userInfo',
        success: function (res) {
          console.log(res)
          getApp().globalData.openid = res.data.openid
          getApp().globalData.nickName = res.data.nickName
          getApp().globalData.avatarUrl = res.data.avatarUrl
          getApp().globalData.is_auth = res.data.is_auth
          getApp().globalData.token = res.data.token
          getApp().globalData.uid = res.data.uid
          //判断用户是否登录
          api
            .isLogin({
              uid: res.data.uid,
            })
            .then((res) => {
              console.log('接口返回:', res)
              if (res.code == true) {
                getApp().globalData.hasLogin = true
                getApp().globalData.uid = res.data.id
                getApp().globalData.nft_address = res.data.nft_address
              } else {
                /* 若token过期后台返回false则先清空本地的缓存 */
                uni.clearStorage()
              }
            })
            .catch((err) => {
              console.log(err)
            })
        },
      })
    }, 1000)
  },
  onShow: function () {
    console.log(getApp().globalData.hasLogin)
    /* 从本地缓存读取数据 */
    // 验证登录token是否过期
    setTimeout(() => {
      uni.getStorage({
        key: 'userInfo',
        success: function (res) {
          console.log(res)
          getApp().globalData.openid = res.data.openid
          getApp().globalData.nickName = res.data.nickName
          getApp().globalData.avatarUrl = res.data.avatarUrl
          getApp().globalData.is_auth = res.data.is_auth
          getApp().globalData.token = res.data.token
          getApp().globalData.uid = res.data.uid
          //判断用户是否登录
        },
      })
    }, 1000)

    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },
}
</script>

<style lang="scss">
@import '@/uni_modules/uview-ui/index.scss';
page {
  background: #181816;
}
img {
  pointer-events: none;
}
//微信小程序
/* 选中后的 背景样式 （红色背景 无边框 可根据UI需求自己修改） */
radio .wx-radio-input.wx-radio-input {
  background-color: #181816 !important;
  border-color: #fff;
  background-clip: content-box !important;

  box-sizing: border-box;
  height: 35rpx !important;
  width: 35rpx !important;
}
radio .wx-radio-input.wx-radio-input-checked {
  background-color: #4effff !important;
  background-clip: content-box !important;
  border: 0 !important;
  box-sizing: border-box;
  height: 35rpx !important;
  width: 35rpx !important;
}

/* 选中后的 对勾样式 （白色对勾 可根据UI需求自己修改） */
radio .wx-radio-input.wx-radio-input-checked::before {
  /* 去除对号 */

  width: 35rpx;
  height: 35rpx;
  border-radius: 50%;
  background-color: #4effff;
}

// H5radio
.radio uni-radio .uni-radio-wrapper .uni-radio-input {
  -webkit-appearance: none;
  appearance: none;
  margin-right: 5px;
  outline: 0;
  border: 1px solid #d1d1d1;
  background-color: #fff;
  border-radius: 50%;
  width: 24rpx !important;
  height: 24rpx !important;
  position: relative;
}
// button通用
uni-button::after {
  border: 0;
}
</style>
